package com.jcooky.tutorfs.proxy.processor.factory;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.jcooky.tutorfs.proxy.processor.MessageProcessor;
import com.jcooky.tutorfs.proxy.processor.ReqMkdirProcessor;
import com.jcooky.tutorfs.proxy.processor.ReqReadProcessor;
import com.jcooky.tutorfs.proxy.processor.ReqRmdirProcessor;
import com.jcooky.tutorfs.proxy.processor.ReqWriteProcessor;
import com.jcooky.tutorfs.proxy.processor.scheduled.ScheduledProcessor;
import com.jcooky.tutorfs.proxy.processor.scheduled.SimpleScheduledProcessor;
import com.jcooky.tutorfs.proxy.protocol.AbstractMessage;
import com.jcooky.tutorfs.proxy.protocol.ReqMkdir;
import com.jcooky.tutorfs.proxy.protocol.ReqRead;
import com.jcooky.tutorfs.proxy.protocol.ReqRmdir;
import com.jcooky.tutorfs.proxy.protocol.ReqWrite;

public class ScheduledProcessorFactory extends AbstractProcessorFactory {
	
	private ExecutorService threadPool = Executors.newCachedThreadPool();
	private AbstractProcessorFactory simpleProcessorFactory = new SimpleProcessorFactory();
	
	
	public <T extends AbstractMessage> MessageProcessor<T> getProcessor(
			int msgType) {
		MessageProcessor<T> processor = simpleProcessorFactory.getProcessor(msgType);
		if (processor == null)
			return null;
		
		ScheduledProcessor<T> scheduledProcessor = new SimpleScheduledProcessor(processor);
		scheduledProcessor.setThreadPool(threadPool);
		
		return scheduledProcessor;
	}

}
